<template>
	<div>
		<div id="app" class="wrapper wrapper-content">
			<div class="row">
				<div>
					<div class="panel panel-primary">
						<div class="panel-body" style="padding: 0px 120px; box-sizing: border-box;">
							<el-form size="small" :model="inputForm" ref="inputForm" v-loading="loading"
								:disabled="formReadOnly">
								<div style="text-align:center">
									<h3 style="font-weight: bold;color: black;font-size:24px">付款申请单</h3>
								</div>
								<table
									style="margin:0 auto;width:80%;margin-top:20px;border-collapse: collapse;margin-bottom:20px">
									<tr style="line-height: 3.5;">
										<td colspan="4"
											style="font-weight: bold;text-align: left;padding-left: 32px;position: relative;font-size: 14px">
											<img src="../../../../../assets/imgs/processManagement/work.png" alt=""
												style="position: absolute;width: 20px;height: 20px;left: 0px;top: 14px;margin-left: 8px">
											基本信息
										</td>
									</tr>
									<tr class="iconHidden">
										<td class="width-15">申请人</td>
										<td class="width-30">
											<el-form-item prop="applyuser.id">
												<user-select :limit='1' :value="inputForm.applyuser.id"
													@getValue='(value) => {inputForm.applyuser.id=value}' disabled>
												</user-select>
											</el-form-item>
										</td>
										<td class="width-15">所属公司</td>
										<td class="width-30">
											<el-form-item prop="company.id">
												<SelectTree ref="company" :props="{
                                                      value: 'id',             // ID字段名
                                                      label: 'name',         // 显示名称
                                                      children: 'children'    // 子级字段名
                                                    }" disabled url="/sys/office/treeData?type=2"
													:value="inputForm.company.id" :clearable="true" :accordion="true"
													@getValue="(value) => {inputForm.company.id=value}" />
											</el-form-item>
										</td>
									</tr>
									<tr class="iconHidden">
										<td class="width-15">申请时间</td>
										<td class="width-30">
											<el-form-item prop="applydate">
												<el-date-picker v-model="inputForm.applydate" type="datetime"
													style="width: 100%;" value-format="yyyy-MM-dd HH:mm:ss"
													placeholder="请选择" disabled></el-date-picker>
											</el-form-item>
										</td>
										<td class="width-15">所属部门</td>
										<td class="width-30">
											<el-form-item prop="depart.id">
												<SelectTree ref="depart" :props="{
                                                      value: 'id',             // ID字段名
                                                      label: 'name',         // 显示名称
                                                      children: 'children'    // 子级字段名
                                                    }" disabled url="/sys/office/treeData?type=2"
													:value="inputForm.depart.id" :clearable="true" :accordion="true"
													@getValue="(value) => {inputForm.depart.id=value}" />
											</el-form-item>
										</td>
									</tr>
									<tr style="line-height: 3.5;">
										<td colspan="4"
											style="font-weight: bold;text-align: left;padding-left: 32px;position: relative;font-size: 14px">
											<img src="../../../../../assets/imgs/processManagement/basic.png" alt=""
												style="position: absolute;width: 20px;height: 20px;left: 0px;top: 14px;margin-left: 8px">
											付款信息
											<span style="margin-left:70px;" v-if="haveAuthority">
												<span style="color:red">账户余额:</span>
												<span v-if="accountBalancesShow" style="padding:0 5px">****</span>
												<span v-if="!accountBalancesShow"
													style="padding:0 5px;font-weight:400;">{{this.accountBalances}}</span>
												<i class="el-icon-view" @click="showOrHidden" style="color:#1296DB"></i>
											</span>
										</td>
									</tr>
									<tr>
										<td colspan="4"
											style="font-weight: bold;text-align: left;padding:10px 32px;position: relative;font-size: 14px">
											<el-radio-group v-model="inputForm.projectpay" @change="clearContract">
												<el-radio label="0">项目付款</el-radio>
												<el-radio label="1">非项目付款</el-radio>
											</el-radio-group>
											<span style="color:green;margin-left:20px"
												v-if="this.actuallymoneyMessage && msgGreen">提示:{{this.actuallymoneyMessage}}</span>
											<span style="color:red;margin-left:20px"
												v-if="this.actuallymoneyMessage && msgRed">提示:{{this.actuallymoneyMessage}}</span>
										</td>
									</tr>
									<tr class="iconHiddens  errorMsg">
										<td class="width-15"><span style="color: red">*&nbsp;</span>合同类型</td>
										<td class="width-30">
											<el-form-item prop="contracttype">
												<el-select v-model="inputForm.contracttype" placeholder="请选择"
													style="width: 100%;" @change="clearChangeContract">
													<el-option
														v-for="item in $dictUtils.getDictList('type_of_contract')"
														:key="item.value" :label="item.label" :value="item.value">
													</el-option>
												</el-select>
											</el-form-item>
										</td>
										<td class="width-15"><span style="color: red">*&nbsp;</span>合同名称</td>
										<td class="width-30" v-if="inputForm.contracttype==0">
											<el-form-item prop="contract">
												<GridSelects title="选择合同" labelName='contractName' labelValue='id'
													:value="inputForm.contract" :limit="1"
													@getValue='getValueName(arguments)' :columns="[
                                        {
                                          prop: 'contractName',
                                          label: '合同'
                                        }]" :searchs="[
                                        {
                                          prop: 'contractName',
                                          label: '合同'
                                        }]" dataListUrl="/sys/oa/contract/findcontract?type=0"
													entityBeanName="buspayContract"
													queryEntityUrl="/dlyrl/oa/buspaycontract/buspayContract/queryById">
												</GridSelects>
											</el-form-item>
										</td>
										<td class="width-30" v-if="inputForm.contracttype==1">
											<el-form-item prop="contract">
												<GridSelects title="选择合同" labelName='contractName' labelValue='id'
													:value="inputForm.contract" :limit="1"
													@getValue='getValueName(arguments)' :columns="[
                                        {
                                          prop: 'contractName',
                                          label: '合同'
                                        },]" :searchs="[
                                        {
                                          prop: 'contractName',
                                          label: '合同'
                                        }]" dataListUrl="/sys/oa/contract/findcontract?type=1"
													entityBeanName="oaProjectContract"
													queryEntityUrl="/dlyrl/oa/propaycontract/propayContract/queryById">
												</GridSelects>
											</el-form-item>
										</td>
										<!-- <td class="width-30" v-if="inputForm.contracttype==2">
                                    <el-form-item  prop="contract.id" :rules="[{required: true, message:'合同不能为空', trigger:['blur','change']}]">
                                       <GridSelect
                                        title="选择合同"
                                        labelName = 'contractName'
                                        labelValue = 'id'
                                        :value = "inputForm.contract.id"
                                        :limit="1"                                    
                                        @getValue='(value) => {inputForm.contract.id=value}'
                                        :columns="[
                                        {
                                          prop: 'contractName',
                                          label: '合同'
                                        },]"
                                        :searchs="[
                                        {
                                          prop: 'contractName',
                                          label: '合同'
                                        }]"
                                        dataListUrl="/sys/oa/contract/findcontract?type=2"
                                        entityBeanName="dispatchContract"
                                        queryEntityUrl="/dlyrl/hr/dispatchcontract/dispatchContract/queryById">
                                      </GridSelect>                                    
                                    </el-form-item>
                                </td>                                             -->
									</tr>
									<tr class="iconHiddens">
										<td class="width-15" v-if="inputForm.projectpay==0"><span
												style="color: red">*&nbsp;</span>项目</td>
										<td class="width-30" v-if="inputForm.projectpay==0">
											<el-form-item prop="associatedproject"
												:rules="[{required: true, message:'项目不能为空', trigger:['blur','change']}]">
												<el-input v-model="inputForm.associatedproject"></el-input>
											</el-form-item>
										</td>
										<td class="width-15" v-if="inputForm.projectpay==1"><span
												style="color: red">*&nbsp;</span>付款类型</td>
										<td class="width-30" v-if="inputForm.projectpay==1">
											<el-form-item prop="payType"
												:rules="[{required: true, message:'付款类型不能为空', trigger:['blur','change']}]">
												<el-cascader placeholder="请选择" v-model="inputForm.payType"
													style="width: 100%;" :props="{
                                              expandTrigger: 'hover',
                                              checkStrictly: true,
                                              label: 'name',
                                              value: 'id',
                                              children: 'children',
                                            }" size="small" ref="bussinessTypes" @change="handleChange" clearable
													@click.native="handleSelect" :popper-class="'cascader1'"
													:options="valueData">
												</el-cascader>
											</el-form-item>
										</td>
										<td class="width-15"><span style="color: red">*&nbsp;</span>付款方式</td>
										<td class="width-30">
											<el-form-item prop="payway"
												:rules="[{required: true, message:'付款方式不能为空', trigger:['blur','change']}]">
												<el-select v-model="inputForm.payway" placeholder="请选择"
													style="width: 100%;" @change="clearBank">
													<el-option v-for="item in $dictUtils.getDictList('payway')"
														:key="item.value" :label="item.label" :value="item.value">
													</el-option>
												</el-select>
											</el-form-item>
										</td>
									</tr>
									<tr class="iconHiddens errorMsg">
										<td class="width-15"><span style="color: red">*&nbsp;</span>付款用途</td>
										<td class="width-30">
											<el-form-item prop="content"
												:rules="[{required: true, message:'付款用途不能为空', trigger:'blur'}]">
												<el-input v-model="inputForm.content"></el-input>
											</el-form-item>
										</td>
										<td class="width-15">供应商</td>
										<td class="width-30">
											<el-form-item prop="supplier.id">
												<GridSelects title="选择供应商" labelName='companyName' labelValue='id'
													:value="inputForm.supplier.id" :limit="1"
													@getValue='(value) => {inputForm.supplier.id=value}' :columns="[
                                      {
                                        prop: 'customerName.companyName',
                                        label: '名称'
                                      }
                                      ]" dataListUrl="/dlyrl/hr/guestsentiment/guestSentiment/list"
													entityBeanName="guestSentiment"
													queryEntityUrl="/dlyrl/hr/guestsentiment/guestSentiment/queryById">
												</GridSelects>
											</el-form-item>
										</td>
									</tr>
									<tr class="iconHiddens" v-if="this.inputForm.payway==1">
										<td class="width-15"><span style="color: red">*&nbsp;</span>收款方</td>
										<td class="width-30">
											<!-- <el-form-item  prop="receivingSide"  :rules="[{required: true, message:'收款方不能为空', trigger:'blur',pattern:/^[\u4e00-\u9fa5a-zA-Z]*$/}]"> -->
											<el-form-item prop="receivingSide"
												:rules="[{required: true, message:'收款方不能为空', trigger:'blur'}]">
												<el-input v-model="inputForm.receivingSide" disabled></el-input>
											</el-form-item>
										</td>
										<td class="width-15"><span style="color: red">*&nbsp;</span>开户行</td>
										<td class="width-30">
											<el-form-item prop="bankname"
												:rules="[{required: true, message:'开户行不能为空', trigger:'blur'}]">
												<el-select v-model="inputForm.bankname" placeholder="请选择"
													style="width: 100%;" disabled>
													<el-option
														v-for="(item,index) in $dictUtils.getDictList('zhaohang_chinese_bank')"
														:key="index" :label="item.label" :value="item.value">
													</el-option>
												</el-select>
											</el-form-item>
										</td>
									</tr>
									<tr class="iconHiddens" v-if="this.inputForm.payway==1">
										<td class="width-15"><span style="color: red">*&nbsp;</span>账号</td>
										<td class="width-30">
											<!-- <el-form-item  prop="bankno" :rules="[{required: true, message:'账号不能为空', trigger:'blur',pattern:/^[0-9]*$/}]"> -->
											<el-form-item prop="bankno"
												:rules="[{required: true, message:'账号不能为空', trigger:'blur'}]">
												<el-input v-model="inputForm.bankno" disabled></el-input>
											</el-form-item>
										</td>
										<td class="width-15">发票类型</td>
										<td class="width-30">
											<el-form-item prop="invoicetype">
												<el-select v-model="inputForm.invoicetype" placeholder="请选择"
													style="width: 100%;">
													<el-option v-for="item in $dictUtils.getDictList('lhinvoice_type')"
														:key="item.value" :label="item.label" :value="item.value">
													</el-option>
												</el-select>
											</el-form-item>
										</td>
									</tr>
									<tr class="iconHidden">
										<td class="width-15"><span style="color: red">*&nbsp;</span>应付总额</td>
										<td class="width-30">
											<el-form-item prop="totalmoney"
												:rules="[{required: true, message:'应付总额不能为空', trigger:'blur'},{validator: validator.isFloatGteZero, trigger:'blur'}]">
												<el-input v-model="inputForm.totalmoney" @input="totalmoneySwitch"
													disabled></el-input>
											</el-form-item>
										</td>
										<td class="width-15">大写金额</td>
										<td class="width-30">
											<el-form-item prop="capsmoney">
												<el-input v-model="inputForm.capsmoney" disabled></el-input>
											</el-form-item>
										</td>
									</tr>
									<tr class="iconHidden">
										<td class="width-15"><span style="color: red">*&nbsp;</span>实付金额</td>
										<td class="width-30">
											<el-form-item prop="actuallymoney"
												:rules="[{required: true, message:'实付总额不能为空', trigger:'blur',pattern: /^\d*\.?(\d|\d{2})$/}]">
												<el-input v-model="inputForm.actuallymoney"
													@input="actuallymoneySwitch"></el-input>
											</el-form-item>
										</td>
										<td class="width-15">大写金额</td>
										<td class="width-30">
											<el-form-item prop="actuallymoneybig">
												<el-input v-model="inputForm.actuallymoneybig" disabled></el-input>
											</el-form-item>
										</td>
									</tr>
									<tr class="iconHidden">
										<td class="width-15"><span style="color: red">*&nbsp;</span>付款比例</td>
										<td class="width-30">
											<el-form-item prop="paymentratio"
												:rules="[{required: true, message:'付款比例不能为空', trigger:'blur'}]">
												<el-input v-model="inputForm.paymentratio" disabled></el-input>
											</el-form-item>
										</td>
										<td class="width-15" v-if="this.inputForm.payway==0">发票类型</td>
										<td class="width-30" v-if="this.inputForm.payway==0">
											<el-form-item prop="invoicetype">
												<el-select v-model="inputForm.invoicetype" placeholder="请选择"
													style="width: 100%;">
													<el-option v-for="item in $dictUtils.getDictList('lhinvoice_type')"
														:key="item.value" :label="item.label" :value="item.value">
													</el-option>
												</el-select>
											</el-form-item>
										</td>
										<td class="width-15" v-if="this.inputForm.payway==1"></td>
										<td class="width-30" v-if="this.inputForm.payway==1"></td>
									</tr>
								</table>
							</el-form>
						</div>
					</div>
				</div>
			</div>
		</div>
		<el-dialog title="账户余额查询" :visible.sync="accountBalancesDialog" width="20%" :before-close="closePwd">
			<el-form :model="accountBalancesForm" size="small" label-width="80px" ref="accountBalancesForms"
				v-loading="accountBalancesLoading">
				<el-row :gutter="15">
					<el-col :span="18">
						<el-form-item label="密码" prop="pwd"
							:rules="[ {required: true, message:'请输入账户密码', trigger:'blur'} ]">
							<el-input v-model="accountBalancesForm.pwd" placeholder="请输出该账号密码" type="password">
							</el-input>
						</el-form-item>
					</el-col>
				</el-row>
			</el-form>
			<span slot="footer" class="dialog-footer">
				<el-button size="small" type="primary" @click="closePwd" plain>关闭</el-button>
				<el-button size="small" type="primary" @click="confirmPwd" plain>确定</el-button>
			</span>
		</el-dialog>
	</div>
</template>
<script>
	import tableStyles from '../../../../../utils/mixins'
	import UserSelect from '@/components/userSelect'
	import SelectTree from '@/components/treeSelect/treeSelect.vue'
	import GridSelect from '@/components/gridSelect'
	import GridSelects from '@/components/gridSelect/index1.vue'
	export default {
		mixins: [tableStyles],
		data() {
			var bankAccountValid = (rule, value, callback) => {
				const strBin =
					"10,18,30,35,37,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,58,60,62,65,68,69,84,87,88,94,95,98,99";
				if (!value) {
					return callback(new Error("收款账户不能为空"));
				} else if (!Number.isInteger(+value)) {
					callback(new Error("银行卡号必须全为数字"));
				} else if (value.trim().length < 12 || value.trim().length > 19) {
					callback(new Error("银行卡号长度必须在12到19之间"));
				} else if (strBin.indexOf(value.substring(0, 2)) === -1) {
					callback(new Error("银行卡号开头6位不符合规范"));
				} else {
					callback();
				}
			};
			return {
				contractId: '', //合同名称的ID
				actuallymoneyMessage: '', //实付金额的提示语句
				radio: '1', //单选
				unpaidAmount: '', //未付款金额
				title: '',
				method: '',
				loading: false,
				inputForm: {
					id: '',
					applyuser: {
						id: ''
					},
					company: {
						id: ''
					},
					applydate: '',
					depart: {
						id: ''
					},
					payType: '',
					payway: '1',
					bankname: '',
					supplier: {
						id: ''
					},
					bankno: '',
					content: '',
					invoicetype: '',
					totalmoney: '',
					capsmoney: '',
					contract: '',
					contracttype: '0',
					actuallymoney: '',
					actuallymoneybig: '',
					paymentratio: '',
					associatedproject: '',
					projectpay: '0', //默认项目付款
					receivingSide: ''
				},
				valueData: [], //报销二，三级类目
				cascaderKey: 1,

				accountBalances: '',
				accountBalancesShow: true, //账户余额
				accountBalancesDialog: false,
				accountBalancesForm: {
					pwd: '',
				},
				accountBalancesLoading: '',
				haveAuthority: false, //账户余额显示与否

				msgGreen: false,
				msgRed: false
			}
		},
		props: {
			businessId: {
				type: String,
				default: ''
			},
			formReadOnly: {
				type: Boolean,
				default: false
			}
		},
		components: {
			UserSelect,
			SelectTree,
			GridSelect,
			GridSelects,
		},
		watch: {
			'businessId': {
				handler(newVal) {
					if (this.$store.state.user.id != '') {
						var users = this.$store.state.user
					} else {
						var users = JSON.parse(sessionStorage.getItem("userInfo"));
					}
					if (this.businessId) {
						this.init(this.businessId);
						this.getHaveAuthority(); //获取是否具有查看账户余额权限
					} else {
						this.$nextTick(() => {
							this.$refs.inputForm.resetFields();
							this.inputForm.applyuser.id = users.id;
							this.inputForm.company.id = users.company.id;
							this.inputForm.depart.id = users.office.id;
							this.inputForm.applydate = this.getNowTime();
							this.getBusssinessType(this.$route.query.id);
						})
					}
				},
				immediate: true,
				deep: false
			},
		},
		created() {
			window.addEventListener("beforeunload", () => {
				sessionStorage.setItem("userInfo", JSON.stringify(this.$store.state.user))
			})
		},
		methods: {
			getValueName(val) {
				// console.log(val,'val')
				this.inputForm.contract = val[0]
				this.inputForm.bankname = val[3]
				this.inputForm.bankno = val[4]
				this.inputForm.totalmoney = val[5]
				this.unpaidAmount = val[6]
				this.contractId = val[7]
				this.inputForm.receivingSide = val[8]
				this.totalmoneySwitch()
				this.$http({
					url: '/dlyrl/oa/buspaycontract/buspayContract/getRatio',
					method: 'get',
					params: {
						buspayId: this.contractId,
						type: this.inputForm.contracttype
					}
				}).then(({
					data
				}) => {
					if (data.success) {
						if (data.ratio == '0') {
							this.actuallymoneyMessage = '您当前不具备付款条件'
							this.msgRed = true;
						} else {
							this.actuallymoneyMessage = '您当前持有' + data.ratio + '付款比例'
							this.msgGreen = true;
						}
					}
					// console.log(data,'------------')          
				})
			},
			//获取是否具有查看账户余额权限
			getHaveAuthority() {
				if (this.$store.state.user.id != '') {
					var users = this.$store.state.user
				} else {
					var users = JSON.parse(sessionStorage.getItem("userInfo"));
				}
				this.$http({
					url: '/accountBalance/getUserAuthority',
					method: 'get',
					params: {
						uid: users.id,
					}
				}).then(({
					data
				}) => {
					if (data && data.success && data.authority == 1) {
						this.haveAuthority = true;
					}
				})

			},
			//余额与****切换
			showOrHidden() {
				this.accountBalancesShow = !this.accountBalancesShow;
				if (!this.accountBalancesShow) {
					this.accountBalances = '';
					this.accountBalancesDialog = true;
				}
			},
			//查询余额关闭
			closePwd() {
				this.accountBalancesShow = true;
				this.accountBalancesDialog = false;
				this.$refs.accountBalancesForms.resetFields();
			},
			//查询余额确认
			confirmPwd() {
				if (this.$store.state.user.id != '') {
					var users = this.$store.state.user
				} else {
					var users = JSON.parse(sessionStorage.getItem("userInfo"));
				}
				this.$refs['accountBalancesForms'].validate((valid) => {
					if (valid) {
						this.accountBalancesLoading = true;
						this.$http({
							url: '/accountBalance/getBalance',
							method: 'get',
							params: {
								uid: users.id,
								company: users.company.id,
								pwd: this.accountBalancesForm.pwd
							}
						}).then(({
							data
						}) => {
							this.accountBalancesLoading = false;
							this.accountBalancesDialog = false;
							this.$refs.accountBalancesForms.resetFields();
							if (data && data.success) {
								this.$message.success(data.msg);
								this.accountBalances = data.balance;
							} else {
								this.accountBalancesShow = true;
							}
						})
					}
				})
			},
			// 搜索城市切换选项
			handleChange(e) {
				this.$refs.bussinessTypes.dropDownVisible = false; //监听值发生变化就关闭它
			},
			//点击label也可以进行选择
			handleSelect(event) {
				var that = this;
				this.$nextTick(() => {
					let d = document.getElementsByClassName("cascader1");
					if (d[0] && !d[0].onclick) {
						d[0].onclick = function(e) {
							if (e.target.className == "el-cascader-node__label") {
								e.target.previousElementSibling.click();
							}
						};
					}
				});
			},
			//得到报销类目等数据
			getBusssinessType(id) {
				this.$http({
					url: `/dlyrl/oa/claimexpenses/claimingExpenses/twoProcess`,
					method: 'get',
					params: {
						company: id,
						// company:'484tf521yg854hg6asyg',
						// id:0
					}
				}).then(({
					data
				}) => {
					if (data && data.success) {
						this.valueData = data.list;
					}
				})
			},
			//实付金额大写
			actuallymoneySwitch() {
				if (this.unpaidAmount.length != 0 && this.inputForm.actuallymoney.length != 0) {
					this.inputForm.paymentratio = (Number(this.inputForm.actuallymoney) / Number(this.unpaidAmount) * 100)
						.toFixed(2) + '%'; //四舍五入去两位小数点  单位h 
				}
				var money = this.inputForm.actuallymoney;
				var cnNums = new Array('零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖');
				//基本单位
				var cnIntRadice = new Array('', '拾', '佰', '仟');
				//对应整数部分扩展单位
				var cnIntUnits = new Array('', '万', '亿', '兆');
				//对应小数部分单位
				var cnDecUnits = new Array('角', '分', '毫', '厘');
				//整数金额时后面跟的字符
				var cnInteger = '整';
				//整型完以后的单位
				var cnIntLast = '元';
				//最大处理的数字
				var maxNum = 999999999999999.9999;
				//金额整数部分
				var integerNum;
				//金额小数部分
				var decimalNum;
				//输出的中文金额字符串
				var chineseStr = '';
				//分离金额后用的数组，预定义
				var parts;
				if (money == '') {
					this.inputForm.actuallymoneybig = chineseStr
				}
				money = parseFloat(money);
				if (money >= maxNum) {
					//超出最大处理数字
					return '';
				}
				if (money == 0) {
					chineseStr = cnNums[0] + cnIntLast + cnInteger;
				}
				//转换为字符串
				money = money.toString();
				if (money.indexOf('.') == -1) {
					integerNum = money;
					decimalNum = '';
				} else {
					parts = money.split('.');
					integerNum = parts[0];
					decimalNum = parts[1].substr(0, 4);
				}
				//获取整型部分转换
				if (parseInt(integerNum, 10) > 0) {
					var zeroCount = 0;
					var IntLen = integerNum.length;
					for (var i = 0; i < IntLen; i++) {
						var n = integerNum.substr(i, 1);
						var p = IntLen - i - 1;
						var q = p / 4;
						var m = p % 4;
						if (n == '0') {
							zeroCount++;
						} else {
							if (zeroCount > 0) {
								chineseStr += cnNums[0];
							}
							//归零
							zeroCount = 0;
							chineseStr += cnNums[parseInt(n)] + cnIntRadice[m];
						}
						if (m == 0 && zeroCount < 4) {
							chineseStr += cnIntUnits[q];
						}
					}
					chineseStr += cnIntLast;
				}
				//小数部分
				if (decimalNum != '') {
					var decLen = decimalNum.length;
					for (var i = 0; i < decLen; i++) {
						var n = decimalNum.substr(i, 1);
						if (n != '0') {
							chineseStr += cnNums[Number(n)] + cnDecUnits[i];
						}
					}
				}
				if (chineseStr == '') {
					chineseStr += cnNums[0] + cnIntLast + cnInteger;
				} else if (decimalNum == '' && money != 0) {
					chineseStr += cnInteger;
				}
				this.inputForm.actuallymoneybig = chineseStr
			},
			//应付总额大写
			totalmoneySwitch() {
				if (this.inputForm.totalmoney.length != 0 && this.inputForm.actuallymoney.length != 0) {
					this.inputForm.paymentratio = (this.inputForm.actuallymoney / this.inputForm.totalmoney).toFixed(2) *
						100 + '%'; //四舍五入去两位小数点  单位h 
				}
				var money = this.inputForm.totalmoney;
				var cnNums = new Array('零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖');
				//基本单位
				var cnIntRadice = new Array('', '拾', '佰', '仟');
				//对应整数部分扩展单位
				var cnIntUnits = new Array('', '万', '亿', '兆');
				//对应小数部分单位
				var cnDecUnits = new Array('角', '分', '毫', '厘');
				//整数金额时后面跟的字符
				var cnInteger = '整';
				//整型完以后的单位
				var cnIntLast = '元';
				//最大处理的数字
				var maxNum = 999999999999999.9999;
				//金额整数部分
				var integerNum;
				//金额小数部分
				var decimalNum;
				//输出的中文金额字符串
				var chineseStr = '';
				//分离金额后用的数组，预定义
				var parts;
				if (money == '') {
					this.inputForm.capsmoney = chineseStr
				}
				money = parseFloat(money);
				if (money >= maxNum) {
					//超出最大处理数字
					return '';
				}
				if (money == 0) {
					chineseStr = cnNums[0] + cnIntLast + cnInteger;
				}
				//转换为字符串
				money = money.toString();
				if (money.indexOf('.') == -1) {
					integerNum = money;
					decimalNum = '';
				} else {
					parts = money.split('.');
					integerNum = parts[0];
					decimalNum = parts[1].substr(0, 4);
				}
				//获取整型部分转换
				if (parseInt(integerNum, 10) > 0) {
					var zeroCount = 0;
					var IntLen = integerNum.length;
					for (var i = 0; i < IntLen; i++) {
						var n = integerNum.substr(i, 1);
						var p = IntLen - i - 1;
						var q = p / 4;
						var m = p % 4;
						if (n == '0') {
							zeroCount++;
						} else {
							if (zeroCount > 0) {
								chineseStr += cnNums[0];
							}
							//归零
							zeroCount = 0;
							chineseStr += cnNums[parseInt(n)] + cnIntRadice[m];
						}
						if (m == 0 && zeroCount < 4) {
							chineseStr += cnIntUnits[q];
						}
					}
					chineseStr += cnIntLast;
				}
				//小数部分
				if (decimalNum != '') {
					var decLen = decimalNum.length;
					for (var i = 0; i < decLen; i++) {
						var n = decimalNum.substr(i, 1);
						if (n != '0') {
							chineseStr += cnNums[Number(n)] + cnDecUnits[i];
						}
					}
				}
				if (chineseStr == '') {
					chineseStr += cnNums[0] + cnIntLast + cnInteger;
				} else if (decimalNum == '' && money != 0) {
					chineseStr += cnInteger;
				}
				this.inputForm.capsmoney = chineseStr
			},
			//单选变化清除项目
			clearContract() {
				// this.inputForm.associatedproject='';
				// this.inputForm.payType='';
				this.$refs.inputForm.resetFields();
				this.inputForm.applyuser.id = this.$store.state.user.id;
				this.inputForm.company.id = this.$store.state.user.company.id;
				this.inputForm.depart.id = this.$store.state.user.office.id;
				this.inputForm.applydate = this.getNowTime();
			},
			// 合同类型变化清除合同
			clearChangeContract() {
				this.inputForm.contract = '';
			},
			//付款方式变化清空开户行和账户
			clearBank() {
				this.inputForm.bankname = '';
				this.inputForm.bankno = '';
				this.inputForm.receivingSide = '';
			},
			init(id) {
				if (id) {
					this.loading = true
					this.inputForm.id = id
					this.$nextTick(() => {
						this.$refs.inputForm.resetFields()
						this.$http({
							url: `/dlyrl/oa/applypay/oaApplypay/queryById?id=${this.inputForm.id}`,
							method: 'get'
						}).then(({
							data
						}) => {
							this.inputForm = this.recover(this.inputForm, data.oaApplypay);
							this.inputForm.payType = data.oaApplypay.payType.split(",");
							this.loading = false;
							// console.log(this.inputForm.company.id,'id')
							this.getBusssinessType(this.inputForm.company.id);
						})
					})
				}
			},
			// 表单提交
			saveForm(callback) {
				this.$refs['inputForm'].validate((valid) => {
					if (valid) {
						if (this.inputForm.projectpay == 1) {
							this.inputForm.payType = this.inputForm.payType.join(",");
						} else {
							this.inputForm.payType = '';
						}
						this.loading = true
						this.$http({
							url: `/dlyrl/oa/applypay/oaApplypay/save`,
							method: 'post',
							data: this.inputForm
						}).then(({
							data
						}) => {
							this.loading = false;
							if (data && data.success) {
								callback(data.businessTable, data.businessId);
								this.$refs.inputForm.resetFields();
								this.inputForm.applyuser.id = this.$store.state.user.id;
								this.inputForm.company.id = this.$store.state.user.company.id;
								this.inputForm.depart.id = this.$store.state.user.office.id;
								this.inputForm.applydate = this.getNowTime();
							}
						})
					}
				})
			}
		}
	}
</script>
